package com.bing.jh.service.impl;

import cn.hutool.core.text.CharSequenceUtil;
import com.bing.bingPro.util.ProvinceUtil;
import com.bing.jh.entity.ProbeDetailEntity;
import com.bing.jh.entity.ProbeRankEntity;
import com.bing.jh.entity.dto.ProbeMissDto;
import com.bing.jh.entity.dto.ProbeMissPageDto;
import com.bing.jh.mapper.NEProbeMissMapper;
import com.bing.jh.service.NEProbeMissService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Version: 4.06
 * @Author: wangmj
 * @Date: 2023/7/13 18:33
 * @Description: 网元探针缺失业务层
 **/
@Service("neProbeMissService")
public class NEProbeMissServiceImpl implements NEProbeMissService {

    @Autowired
    private NEProbeMissMapper neProbeMissMapper;


/*    @Autowired
    private GeneralConfigService generalConfigService;

    @Autowired
    private RegionInfoServiceImpl regionInfoService;

    @Resource
    private GeneralConfigMapper configMapper;*/



    @Override
    public List<ProbeRankEntity> queryIndexRankingChart(ProbeMissDto probeMissDto) {
        String ne = probeMissDto.getNe();
        List<ProbeRankEntity> list = null;
        String provinceName = probeMissDto.getProvinceName();
        String cityName = probeMissDto.getCityName();
        String regionName = probeMissDto.getRegionName();
        if (StringUtil.isEmpty(cityName) && !("bras".equals(ne) && StringUtil.isNotEmpty(provinceName))) {
            list = neProbeMissMapper.queryIndexRankingData(probeMissDto);
            if (probeMissDto.getTimeGranularity()==0) {
                list.forEach(probeRankEntity -> {
                    probeMissDto.setKeyProvince(ProvinceUtil.getKeyProvince(probeRankEntity.getRegion()));
                });
            }
        } else if (StringUtil.isEmpty(regionName) || ("bras".equals(ne) && StringUtil.isNotEmpty(provinceName))) {
            list = neProbeMissMapper.queryIndexRankingDataRegion(probeMissDto);
            if (probeMissDto.getTimeGranularity()==0) {
                list.forEach(probeRankEntity -> {
                    if (CharSequenceUtil.isNotEmpty(probeMissDto.getCityName())) {
                        probeMissDto.setRegionName(probeRankEntity.getRegion());
                    } else if (CharSequenceUtil.isNotEmpty(probeMissDto.getProvinceName())&&CharSequenceUtil.isEmpty(probeMissDto.getCityName())) {
                        probeMissDto.setCityName(probeRankEntity.getRegion());
                    }

                    Integer count = neProbeMissMapper.queryRankingDataRegionCount(probeMissDto);
                    if (CharSequenceUtil.isNotEmpty(probeMissDto.getCityName())) {
                        probeMissDto.setRegionName(null);
                    } else if (CharSequenceUtil.isNotEmpty(probeMissDto.getProvinceName())&&CharSequenceUtil.isNotEmpty(probeMissDto.getCityName())) {
                        probeMissDto.setCityName(null);
                    }
                    if (count != 0 && (CharSequenceUtil.isEmpty(probeRankEntity.getExcIhguNum()) || probeRankEntity.getExcIhguNum().equals("0"))) {
                        probeRankEntity.setExcIhguNum("0");
                    }
                });
            }
        }
        return list;
    }


    @Override
    public PageInfo<ProbeDetailEntity> queryDetailData(ProbeMissPageDto dto) {
        Integer count = neProbeMissMapper.queryRankingDataRegionCount(dto);
        return PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).doSelectPageInfo(() -> {
            this.neProbeMissMapper.queryDetailData(dto);
        });
    }



}
